﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Ewk.Runtime.Serialization.UnitTests.Records.CharacterSeparated;
using Ewk.Runtime.Serialization.UnitTests.Records.PositionBased;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ewk.Runtime.Serialization;
using Ewk.Runtime.Serialization.UnitTests.Records;

namespace Ewk.Runtime.Serialization.UnitTests
{
    [TestClass]
    public class DatarecordSerializerTests
    {
        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void DatarecordSerializer_can_be_initialized_with_a_typeParameter_that_is_decorated_with_a_DaterecordAttribute()
        {
            var serializer = new DatarecordSerializer<PositionBasedTestDatarecord>();
            Assert.IsInstanceOfType(serializer, typeof(DatarecordSerializer<PositionBasedTestDatarecord>));
        }

        [TestMethod, ExpectedException(typeof(DatarecordNotDefinedException))]
        public void DatarecordSerializer_cannot_serialize_an_instance_of_a_type_without_a_DatarecordAttribute()
        {
            new DatarecordSerializer<UndefinedTestDatarecord>();
        }

        [TestMethod, ExpectedException(typeof(DatarecordWithoutDatafieldsException))]
        public void DatarecordSerializer_cannot_serialize_an_instance_of_a_type_without_properties_with_a_DatafieldAttributes()
        {
            new DatarecordSerializer<PositionBasedTestDatarecordWithoutFields>();
        }

        [TestMethod, ExpectedException(typeof(DatafieldTypeException))]
        public void DatarecordSerializer_cannot_serialize_an_instance_of_a_PositionBasedTestDatarecord_type_with_a_CharacterSeparatedField()
        {
            new DatarecordSerializer<PositionBasedTestDatarecordWithCharacterSeparatedField>();
        }

        [TestMethod, ExpectedException(typeof(DatafieldTypeException))]
        public void DatarecordSerializer_cannot_serialize_an_instance_of_a_CharacterSeparatedTestDatarecord_type_with_a_PositionBasedField()
        {
            new DatarecordSerializer<CharacterSeparatedTestDatarecordWithPositionBasedField>();
        }

        [TestMethod, ExpectedException(typeof(DatafieldOverlapException))]
        public void DatarecordSerializer_cannot_serialize_an_instance_of_a_PositionBasedTestDatarecord_with_overlapping_fields()
        {
            new DatarecordSerializer<PositionBasedTestDatarecordWithOverlappingFields>();
        }

        [TestMethod, ExpectedException(typeof(DatafieldOverflowException))]
        public void DatarecordSerializer_cannot_serialize_an_instance_of_a_PositionBasedTestDatarecord_with_overflowing_fields()
        {
            new DatarecordSerializer<PositionBasedTestDatarecordWithOverflowingFields>();
        }

        [TestMethod]
        public void DatarecordSerializer_can_serialize_an_instance_of_a_PositionBasedTestDatarecord_with_a_gap_between_fields()
        {
            var serializer = new DatarecordSerializer<PositionBasedTestDatarecordWithGapBetweenFields>();
            Assert.IsInstanceOfType(serializer, typeof(DatarecordSerializer<PositionBasedTestDatarecordWithGapBetweenFields>));
        }

        [TestMethod, ExpectedException(typeof(DatafieldOverlapException))]
        public void DatarecordSerializer_cannot_serialize_an_instance_of_a_CharacterSeparatedTestDatarecord_with_fields_that_have_the_same_SerialNumber()
        {
            new DatarecordSerializer<CharacterSeparatedTestDatarecordWithDuplicateSerialNumbers>();
        }

    }
}
